package com.kaiyidiannao.model.req.model;

import android.text.TextUtils;
import android.util.Log;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.model.Result;
import com.kaiyidiannao.model.req.base.BaseCommand;

import java.util.HashMap;

/**
 *   湊對去 - 評論 添加 异步请求
 */
public class PostTourCommentAdd extends BaseCommand {

    //mid=31&itemid=1
    private String item_title;
    private String userid;
    private String itemid;
    private String content;
    private String qid; //父评论

    private static final String TAG = "PostTourComment";

    /**
     * 添加一级评论
     * @param itemid
     * @param content
     */
    public PostTourCommentAdd(String item_title,String userid, String itemid, String content) {
        this.item_title = item_title;
        this.userid = userid;
        this.itemid = itemid;
        this.content = content;
    }

    /**
     * 添加子评论
     * @param itemid
     * @param content
     * @param qid
     */
    public PostTourCommentAdd(String item_title, String userid, String itemid, String content, String qid) {
        this.item_title = item_title;
        this.userid = userid;
        this.itemid = itemid;
        this.content = content;
        this.qid = qid;
    }

    @Override
    public String getRequestUrl() {
        return DataCenter.GET_TOUT_comment_ADDRESS;
    }

    @Override
    public HashMap<String, String> getRequestParamters() {
        HashMap<String, String> paramters = new HashMap<String, String>();
        paramters.put("item_title", item_title);
        paramters.put("mid", "31");
        paramters.put("comment", "1");
        paramters.put("itemid", itemid);
        paramters.put("content", content);
        paramters.put("userid", userid);
        if (qid != null  && !TextUtils.isEmpty(qid)) {
            paramters.put("qid", qid);
        }
        return paramters;
    }

    @Override
    public Result go(String url, HashMap<String, String> paramters) { // 联网时后台执行
        // 根据请求参数返回请求数据
        return HttpUtils.postByHttpClient(url, paramters);
    }

    @Override
    public void yes(Result result) { //后台执行完毕后执行
        super.yes(result);
        Log.d(DataCenter.LOG_INFO, "PostTourCommentAdd.yes()");
        Log.d(TAG, result.object.toString());
        DataCenter.getInstance().callBacks(DataCenter.flag.GET_TOUR_COMMENT_ADD_SUCESS);
    }

    @Override
    public void no(Result result) {
        super.no(result);
        Log.d(DataCenter.LOG_ERROR, "PostTourCommentAdd.no()");
        DataCenter.getInstance().callBacks(DataCenter.flag.GET_TOUR_COMMENT_ADD_FAILED);

    }
}